package com.huabo.audit.controller;

import java.math.BigDecimal;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.hbfk.util.JsonBean;
import com.hbfk.util.ResponseFormat;
import com.huabo.audit.oracle.entity.TblNbsjPlanProject;
import com.huabo.audit.oracle.entity.TblNbsjRefopm;
import com.huabo.audit.oracle.entity.TblNbsjReformSolution;
import com.huabo.audit.oracle.entity.TblNbsjStaffscore;
import com.huabo.audit.oracle.entity.TblNbsjStaffscoreDetails;
import com.huabo.audit.oracle.mapper.TblNbsjStaffscoreDetailsMapper;
import com.huabo.audit.oracle.vo.TblnbsjProjectVo;
import com.huabo.audit.service.TblNbsjProjectService;
import com.huabo.audit.service.TblNbsjStaffscoreService;
import com.huabo.audit.service.TblStaffService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RestController
@Api(value = "人员评分", tags = {"人员评分接口"})
@RequestMapping(value = "/audit/Staffscore")
public class TblNbsjStaffscoreController {

    @Autowired
    TblNbsjStaffscoreService tblNbsjStaffscoreService;

    @Autowired
    TblNbsjStaffscoreDetailsMapper tblNbsjStaffscoreDetailsMapper;
    
    @Autowired
    TblStaffService staffservice;
    
    @Autowired
    TblNbsjProjectService projectService;
    
    @GetMapping("/getpjprojectList")
    @ApiOperation("评价管理-选择人项目")
    public JsonBean getNbsjProjectPageList(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
   		@ApiParam(name="pageNumber",value="分页当前页数",required=false)@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
   		@ApiParam(name="pageSize",value="每页记录数",required=false)@RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
   		@ApiParam(name="projectStartDate",value="项目开始时间 格式年-月-日",required=false)@RequestParam(value = "projectStartDate", required = false) String projectStartDate,
   		@ApiParam(name="projectEndDate",value="项目结束时间 格式年-月-日",required=false)@RequestParam(value = "projectEndDate", required = false) String projectEndDate,
   		@ApiParam(name="staffid",value="选择的人员id",required=false)@RequestParam(value = "staffid", required = false) Integer staffid,
   		TblnbsjProjectVo project) {
    	JsonBean jsonBean = null;
    	try {
    		if(staffid!=null) {
    			project.setStaffId(staffid);
    		}
			jsonBean = projectService.getNbsjProjecGdtPageList(token,pageNumber,pageSize,project,projectStartDate,projectEndDate);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
    
    
    
    @GetMapping("/getpjuserList")
    @ApiOperation("评价管理-选择人员分页")
    public JsonBean getpjuserList(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
   		@ApiParam(name="pageNumber",value="分页当前页数",required=false)@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
   		@ApiParam(name="pageSize",value="每页记录数",required=false)@RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
   		@ApiParam(name="username",value="用户名",required=false) @RequestParam(value = "username", required = false) String username,
   	    @ApiParam(name="realname",value="真实姓名",required=false) @RequestParam(value = "realname", required = false) String realname) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean =staffservice.findByAllPageBean(username, pageNumber, pageSize, token, realname);
		} catch (Exception e) {
			e.printStackTrace();
			ResponseFormat.retParam(0,1000,e.getMessage());
		}
        return jsonBean;
    }
    
    
    
    @GetMapping("/getscoreList")
    @ApiOperation("评价管理-评分列表分页")
    public JsonBean getscoreList(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
   		@ApiParam(name="pageNumber",value="分页当前页数",required=false)@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
   		@ApiParam(name="pageSize",value="每页记录数",required=false)@RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
   		@ApiParam(name="staffid",value="关联人员id",required=false) @RequestParam(value = "staffid", required = false) BigDecimal staffid,
   	    @ApiParam(name="projectname",value="项目名称",required=false) @RequestParam(value = "projectname", required = false) String projectname) {
    	JsonBean jsonBean = null;
    	try {
    		TblNbsjStaffscore re=new TblNbsjStaffscore();
    		re.setAuditors(staffid);
    		re.setAuditProjectName(projectname);
			jsonBean =tblNbsjStaffscoreService.findAll(re, pageNumber, pageSize, token);
		} catch (Exception e) {
			e.printStackTrace();
			ResponseFormat.retParam(0,1000,e.getMessage());
		}
        return jsonBean;
    }
    
    @GetMapping("/getScoreDetail")
    @ApiOperation("评价管理-查看详情信息")
    public JsonBean getAuditPlanInfo(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="staffScoreid",value="评价主键id",required=true)@RequestParam(value = "staffScoreid", required = true) BigDecimal staffScoreid) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean = tblNbsjStaffscoreService.getAttListByStaffScoreid(token, staffScoreid);
		} catch (Exception e) {
			e.printStackTrace();
			ResponseFormat.retParam(0,1000,e.getMessage());
		}
        return jsonBean;
    }
    
    
    @RequestMapping(value = "/mergeScoreInfo", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
   	@ApiOperation(value = "评价管理-新增或修改")
   	public JsonBean mergePlanProjectManageInfoList(HttpServletRequest request,
   			 @ApiParam(name="staffScoreid",value="评价主键 ，如果主键为空则新增信息",required=false) BigDecimal staffScoreid,
   			@ApiParam(name="score",value="评价实体",required=true)TblNbsjStaffscore re,
   			 @ApiParam(name="detailListJson",value="评分详情",required=true) @RequestParam(value = "detailListJson", required = true)String detailListJson,
   			 @ApiParam(name="token",value="登录用户token",required=false) @RequestHeader("token")String token)throws Exception{
   		 JsonBean jsonBean = null;
   			try {
   			List<TblNbsjStaffscoreDetails> list = JSONArray.parseArray(detailListJson,TblNbsjStaffscoreDetails.class);
   				jsonBean = this.tblNbsjStaffscoreService.saveOrUpdate(re, token, staffScoreid, list);
   			} catch (Exception e) {
   				e.printStackTrace();
   				ResponseFormat.retParam(1,1000,e.getMessage());
   			}
   			return jsonBean;
   	} 
    
    
    @RequestMapping(value = "/delScoreInfo", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
   	@ApiOperation(value = "评价管理-删除信息")
       public JsonBean delSolutionAttInfo(HttpServletRequest request,
       		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
       		@ApiParam(name="staffScoreid",value="评价管理ID",required=false) @RequestParam(value = "staffScoreid", required = false) BigDecimal staffScoreid
       		//@ApiParam(name="staffScoreid",value="评价管理ID ",required=true)  BigDecimal staffScoreid
       		) {
       	JsonBean jsonBean = null;
   		try {
   			jsonBean = this.tblNbsjStaffscoreService.delete(staffScoreid, token);
   		} catch (Exception e) {
   			e.printStackTrace();
   			ResponseFormat.retParam(0,1000,e.getMessage());
   		}
   		return jsonBean;
       }
    
    
}
